<?php
$config = [
    'id' => APP_ID,
    'basePath' => YII_PROJECT_ROOT.DIRECTORY_SEPARATOR.APP_ID,
    'controllerNamespace' => APP_ID.'\controllers',
    'aliases' => [
        '@bower' => '@vendor/bower-asset',
        '@npm'   => '@vendor/npm-asset',
    ],
    'vendorPath' => YII_PROJECT_ROOT . '/vendor',
    'runtimePath' => Yii::getAlias("@common/runtime/" . APP_ID),
    'timeZone' => 'PRC', // 中国时区
    'charset' => 'UTF-8', // 默认, 万国码
    'language' => 'zh-CN', // 简体中文
    'bootstrap' => ['queue', 'log'],
    'components' => [
        'formatter' => [
            'dateFormat' => 'php:Y-m-d',
            'datetimeFormat' => 'php:Y-m-d H:i:s',
            'timeFormat' => 'php:H:i:s',
        ],
        'redis' => [
            'class' => 'yii\redis\Connection',
            'hostname' => '127.0.0.1',
            'port' => '6379',
            'database' => '14',
        ],
        'cache' => [
            'class' => 'yii\redis\Cache',
            'keyPrefix' => "lzdls:cache:",
        ],
        'session' => [
            'class' => 'yii\redis\Session',
            'keyPrefix' => "lzdls:session:",
        ],
        'mutex' => [
            'class' => 'yii\redis\Mutex',
        ],
        'queue' => [
            'class' => 'yii\queue\redis\Queue',
            'channel' => 'lzdls:queue:',
            'as log' => [
                'class' => 'yii\queue\LogBehavior',
            ],
        ],
        'log' => [
            'class' => 'yii\log\Dispatcher',
            'traceLevel' => YII_DEBUG ? 3 : 0,
            'targets' => [
                [
                    'class' => 'yii\log\DbTarget',
                    'db' => 'db',
                    'logTable' => '{{%log}}',
                    'levels' => YII_DEBUG ? ['error', 'warning', /*'trace'*/] : ['error'],
                ],
            ],
        ],
        'wMimeTypes' => [
            'class' => 'common\wodrow\mime_types\WMimeTypes',
        ],
        'fs' => [
            'class' => 'common\components\fs\LocalFs',
        ],
        'urlManagerApi' => [
            'class' => 'yii\web\UrlManager',
            'cache' => false,
            'baseUrl' => THIS_SERVER_BASE_URI.'/api',
            'hostInfo' => THIS_SERVER_BASE_URI,
            'enablePrettyUrl' => true,
            'showScriptName' => false,
        ],
        'urlManagerXcxApi' => [
            'class' => 'yii\web\UrlManager',
            'cache' => false,
            'baseUrl' => THIS_SERVER_BASE_URI.'/xcxApi',
            'hostInfo' => THIS_SERVER_BASE_URI,
            'enablePrettyUrl' => true,
            'showScriptName' => false,
        ],
        'urlManagerAdminApi' => [
            'class' => 'yii\web\UrlManager',
            'cache' => false,
            'baseUrl' => THIS_SERVER_BASE_URI.'/adminApi',
            'hostInfo' => THIS_SERVER_BASE_URI,
            'enablePrettyUrl' => true,
            'showScriptName' => false,
        ],
        'urlManagerBackend' => [
            'class' => 'yii\web\UrlManager',
            'cache' => false,
            'baseUrl' => THIS_SERVER_BASE_URI.'/backend',
            'hostInfo' => THIS_SERVER_BASE_URI,
            'enablePrettyUrl' => true,
            'enableStrictParsing' => true,
            'showScriptName' => false,
            'rules' => [
                //基本路径
                "GET,POST,PUT,DELETE <controller:[\w-]+>/<action:[\w-]+>" => "<controller>/<action>",
                //模块化的路径
                "GET,POST,PUT,DELETE <module:[\w-]+>/<controller:[\w-]+>/<action:[\w-]+>" => "<module>/<controller>/<action>",
                //带版本号
                "GET,POST,PUT,DELETE <version:[\w-]+>/<controller:[\w-]+>/<action:[\w-]+>" => "<version>/<controller>/<action>",
                "GET,POST,PUT,DELETE <version:[\w-]+>/<module:[\w-]+>/<controller:[\w-]+>/<action:[\w-]+>" => "<version>/<module>/<controller>/<action>",
            ],
        ],
        'urlManagerAdmin' => [
            'class' => 'yii\web\UrlManager',
            'cache' => false,
            'baseUrl' => THIS_SERVER_BASE_URI.'/admin',
            'hostInfo' => THIS_SERVER_BASE_URI,
            'enablePrettyUrl' => true,
            'showScriptName' => false,
        ],
        'urlManagerHome' => [
            'class' => 'yii\web\UrlManager',
            'cache' => false,
            'baseUrl' => THIS_SERVER_BASE_URI.'/home',
            'hostInfo' => THIS_SERVER_BASE_URI,
            'enablePrettyUrl' => true,
            'showScriptName' => false,
        ],
    ],
    'params' => [
        'isCheckNonce' => true,
        'isCheckTime' => true,
        'isCheckSign' => true,
    ],
];

if (APP_ID != 'console') {
    $urlManagerComponentName = "urlManager" . ucfirst(APP_ID);
    $config['components']['urlManager'] = $config['components'][$urlManagerComponentName];
    if (in_array(APP_ID, ['api', 'xcxApi', 'adminApi'])) {
        $config['modules']['route'] = 'common\components\fast_api\modules\RouteModule';
    } else {
        $config['modules']['gridview'] = 'kartik\grid\Module';
    }
}

return $config;
